<?php
/**
 * Created by PhpStorm.
 * User: 69548
 * Date: 2018/8/17
 * Time: 14:31
 */
namespace app\wap\controller;

use think\Controller;
use app\wap\model\City as M;


class Index extends Controller
{
    public $member_pcode='';

    public function _initialize()
    {
        $this->member_pcode= input('uid');
    }


    public function index(){
        header('Access-Control-Allow-Origin:*');

        $partner_id = input('partner_id');

        $m = new M();
        $date = $m->index($this->member_pcode,$partner_id);

        return json_encode($date);
    }


    public function city()
    {
        header('Access-Control-Allow-Origin:*');
        $city=[];
        $fu= db('city')->where('groupid','0')->where('show',1)->where('deleted',0)->select();
        if (!empty($fu)){
            foreach ($fu as $v){
                $child= db('city')
                    ->where('groupid',$v['id'])
                    ->where('show','1')
                    ->where('deleted',0)
                    ->field('name,eng_name,id as city_id')
                    ->order("sort_weight desc")
                    ->select();
                $city[]=
                    [
                        'name'=> $v['name'],
                        'id'=>$v['id'],
                        'data'=>$child,
                    ];
            }

            $shu=[
                'code'=>0,
                'msg'=>'请求成功',
                'data'=>$city,
                'member_pcode'=>$this->member_pcode
            ];
        }else{
            $shu=[
                'code'=>1,
                'msg'=>'请求失败',
                'data'=>[]
            ];
        }

        return json_encode($shu);
    }





}